package t4tools.dru.trim;

import java.util.Calendar;
import java.util.Date;

public class TrimDate {

	public static long trim(Date date, DatePart toPart) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		for (DatePart part : DatePart.values()) {
			if (part.equals(toPart)) {
				break;
			}
			calendar.set(part.getCalendarField(), calendar.getActualMinimum(part.getCalendarField()));
		}
		return calendar.getTimeInMillis();
	}
}
